import { Component, OnInit } from '@angular/core';
import { ActivatedRoute, Router } from '@angular/router';
import { HttpService } from '@core/services/http.service';
import { NzMessageService, NzModalService } from 'ng-zorro-antd';



@Component({
    selector: 'app-viewcrouse',
    templateUrl: './viewcrouse.component.html',
    styleUrls: ['./viewcrouse.component.less']
})
export class ViewcrouseComponent implements OnInit {

    constructor(private msg: NzMessageService, private Http: HttpService, public router: Router, public route: ActivatedRoute) { }

    CourseDataList = [];
    isCloud = '';
    isUse = '';
    cour_id = '';
    position = 'left';
    IP_PORT = this.Http.IP_PORT;
    choiceId = '';

    ngOnInit() {
        this.route.queryParams.subscribe(res => {
            this.isCloud = res.isCloud;
            this.isUse = res.isUse;
            this.cour_id = res.cour_id;

            this.Http.previewCourseChapter({ cours_id: res.cour_id }).subscribe(c => {
                for (let i = 0; i < c['list'].length; i++) {
                    c['list'][i]['isChange'] = true;
                    c['list'][i]['isNew'] = false;
                    var val = c['list'][i];
                    var list = val['checkList'];
                    var temp = [];
                    for (let j = 0; j < list.length; j++) {
                        var item = list[j];
                        if (item["isCheck"] === true) {
                            temp.push(item);
                        }
                    }
                    val['checkList'] = temp;
                    c['list'][i] = val;
                }
                this.CourseDataList = [];
                this.CourseDataList = this.CourseDataList.concat(c['list']);
                console.log(this.CourseDataList);
            });
        });
    }

    preview(p_id, isCloud) {
        // if (this.isUse === 'true') {
        this.router.navigate(['/xiangmu/full/advance'], { relativeTo: this.route, queryParams: { p_id: p_id, isCloud: isCloud, isUse: this.isUse } });
        // } else {
        // this.msg.info('该课程尚不可用，无法查看所有项目！');
        // }
    }

    goback() {
        history.back();
    }

    TabClick(id) {
        this.choiceId = id;
    }
}
